package com.wyd.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 雷哥
 * @Date: 2020/10/07/23:27
 * @Description:
 */
@Configuration
public class FanoutConfig {

  /**
   * 声明交换机
   */
  @Bean
  public FanoutExchange fanoutExchange(){
    FanoutExchange fanoutExchange=new FanoutExchange("logs");
    return fanoutExchange;
  }

  /**
   * 声明队列1
   */
  @Bean
  public Queue fanoutQueue1(){
    return new Queue("fanout_queue1");
  }

  /**
   * 声明队列2
   */
  @Bean
  public Queue fanoutQueue2(){
    return new Queue("fanout_queue2");
  }

  /**
   * 把队列1绑定到交换机里面
   */
  @Bean
  public Binding binding1(){
    Binding binding= BindingBuilder.bind(fanoutQueue1())
        .to(fanoutExchange());
    return binding;
  }

  /**
   * 把队列2绑定到交换机里面
   */
  @Bean
  public Binding binding2(){
    Binding binding= BindingBuilder.bind(fanoutQueue2())
        .to(fanoutExchange());
    return binding;
  }

}
